<?php
/**
 * Created by PhpStorm.
 * User: Dave
 * Date: 2018/8/24
 * Time: 10:52
 */

use Biz\model\ShopCarouselBanner as mShopCarouselBanner;
use Biz\service\activity\MealInfo as sMealInfo;
use Biz\service\CarouselBanner as sCarouselBanner;
use Biz\tools\GoodsExposureLog;
use Doraemon\tools\ActionLog;


/**
 * @deprecated
 */
class MealListAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $shopId = $this->getRequest()->getQuery('shop_id');
        $goodsId = $this->getRequest()->getQuery('goods_id');
        if (empty($shopId) && empty($goodsId)) {
            throw new \Exception('请求参数异常');
        }

        $bannerInfo = sCarouselBanner::getBannerByType(mShopCarouselBanner::TYPE_MEAL);
        $result['list']['banner'] = $bannerInfo ? array_shift($bannerInfo) : (object)[];
        if (empty($goodsId)) {
            $result['list']['meal'] = sMealInfo::mealListByShopId($shopId);
            ActionLog::log($this->uid, ['shop_id' => $shopId], ActionLog::BIZ_MEAL_LIST);
        } else {
            $result['list']['meal'] = sMealInfo::mealListByGoodsId($goodsId);
            ActionLog::log($this->uid, ['goods_id' => $goodsId], ActionLog::BIZ_MEAL_LIST);
        }


        $this->setSuccess($result);
        GoodsExposureLog::addLog($this->getRequest(), $result);
    }
}